#ifndef prs_FrmButton_H
#define prs_FrmButton_H

//#include "prs_FrmFunc.h"
//#include "prs_FrmRules.h"
//#include "prs_FrmGeom.h"

#include "prs_Rule.h"
#include "prs_FrmControl.h"
#include "prs_FrmUseTemplate.h"
#include "prs_FrmButtonStyle.h"
#include "frm_control_TButton.h"

namespace prs {

///////////////////////////////////////////////////////////////////////////////
struct TNodeFrmButton;
///////////////////////////////////////////////////////////////////////////////

struct TNodeFrmButtonControl : public frm::control::TButton
{
  TNodeFrmButtonControl(
    frm::control::TWindow &Window,
    TNodeFrmButton &Node
  ):TButton(Window),node(Node) {}
  //
  virtual void Click();
  
private:  
  TNodeFrmButton &node;
};

///////////////////////////////////////////////////////////////////////////////

struct TMessage_ClickFrmButton : public TMessage_Base
{
  TNodeFrmButton *Sender;
  //
  TMessage_ClickFrmButton() {
    Sender = NULL;
  }
};

///////////////////////////////////////////////////////////////////////////////

struct TNodeFrmButton : public TNodeFrmControl
{
  DECLARE_ClientNode()
  //
  typedef TNodeFrmButtonStyle   TStyle;
  typedef TNodeFrmButtonControl TControl;
  //
  TAttrNodeType<nodeType_Button> NodeType;
  TAttrPointerNoCopy<attrName_Control,TNodeFrmButtonControl*> Control;
  //
  TNodeFrmButton() : NodeType(this),Control(this) {}
 ~TNodeFrmButton() { delete Control.GetValue();}
  //
  TNodeFrmButtonControl *BuildControl(
    frm::control::TPanel *ParentControl
  );
};
                   
///////////////////////////////////////////////////////////////////////////////

struct TRuleFrmButton : public snt::TRule
{
  TRuleFrmButton(
    snt::text::TContext &Context,
    svl::TVariant &VParentNode,
    TRuleFrmChildrenBase &RChildren,
    TRuleSetNodeIdOptionally &RSetNodeIdOptionally,
    TRuleFrmGeom &RFrmGeom,
    TRuleSetAttrValue &RSetAttrValue,
    TRuleSetStyle &RStyle
  );

private:  
  TNodeFrmButton *GetNode() { return dynamic_cast<TNodeFrmButton*>(vParentNode.Pointer());}
  //
  void FSetGeometry(snt::TParams &Params) { rGeometry.SetGeom( &GetNode()->Geometry.Value );}
  //
  bool FSetParamControlId(TRuleSetAttrValue::TFuncValueIdentParams &Params) {
    return TNodeDefTemplate::AddLinkAttrByParamId(
      Params.Attr,TFrmStringValue(),Params.Ident,Params.OutError
    );
  }
  //
  svl::TVariant &vParentNode;
  TRuleFrmGeom &rGeometry;
  snt::TRule  RAttr,RAttr1;
  snt::TAlter AAttr1;
  svl_Except;
};

///////////////////////////////////////////////////////////////////////////////
}

#endif
